﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BalanceCenter_AdminMessageBoard : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            //Response.Write(_User.Competences.CompetencesList.ToString());
            //Response.End();
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestCompetences = Competences.BuildCompetencesList(Competences.MemberService);
        RequestLoginPage = "BalanceCenter/AdminMessageBoard.aspx";

        base.OnInit(e);
    }

    #endregion

    private void BindData()
    {
        //DataTable dt = DAL.Views.V_MessageBoard.Select("", "ToUserID = " + _User.ID, "[DateTime] desc");

        DataTable dt = DAL.Views.V_MessageBoard.Select("", "", "[DateTime] desc");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.NoData, "对不起，数据库读写错误", this.GetType().BaseType.FullName);

            return;
        }

        dt.Columns.Add("Content2", typeof(System.String));
        dt.Columns.Add("Reply2", typeof(System.String));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            string Content = "", Reply = "";
            try
            {
                Content = ShoveEL._Convert.ToHtmlCode(ShoveEL._String.Decompress((byte[])dt.Rows[i]["Content"]));
            }
            catch { }
            try
            {
                Reply = ShoveEL._String.Decompress((byte[])dt.Rows[i]["Reply"]);
            }
            catch { }

            dt.Rows[i]["Content2"] = Content;
            dt.Rows[i]["Reply2"] = Reply;

            dt.AcceptChanges();
        }

        g.DataSource = dt.DefaultView;
        g.DataBind();
    }

    protected void g_PageIndexChanged(object sender, System.EventArgs e)
    {
        BindData();
    }

    protected void g_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "btnReply")
        {
            System.Web.UI.HtmlControls.HtmlInputHidden tbID = (System.Web.UI.HtmlControls.HtmlInputHidden)e.Item.FindControl("tbID");
            System.Web.UI.WebControls.TextBox tbReply = (System.Web.UI.WebControls.TextBox)e.Item.FindControl("tbReply");

            if (DAL.Tables.T_MessageBoard.Update("[id] =" + tbID.Value, 0, false, 0, false, DateTime.Now, false, "", false, ShoveEL._String.Compress("a"), false, DateTime.Now, true, ShoveEL._String.Compress(tbReply.Text), true, "", false, 1, false) < 0)
            {
                PublicFunction.GoError(ErrorNumber.Unknow, "回复信息添加失败", this.GetType().BaseType.FullName);

                return;
            }


            BindData();
            ShoveEL._Web.JavaScript.Alert(this.Page, "回复保存成功。");

            return;
        }

        if (e.CommandName == "btnDelete")
        {
            System.Web.UI.HtmlControls.HtmlInputHidden tbID = (System.Web.UI.HtmlControls.HtmlInputHidden)e.Item.FindControl("tbID");

            if (DAL.Tables.T_MessageBoard.Delete("[id] = " + tbID.Value) < 0)
            {
                PublicFunction.GoError(ErrorNumber.Unknow, "留言信息删除失败", this.GetType().BaseType.FullName);

                return;
            }

            BindData();

            return;
        }
    }
}
